package com.wjb.xietong.server.topic;

import org.json.JSONObject;

import com.wjb.xietong.server.BaseResponseDataParse;
import com.wjb.xietong.server.HeaderInfoResponse;
import com.wjb.xietong.util.IDs;
import com.wjb.xietong.util.LogD;

public class ReplyResponse extends BaseResponseDataParse {

	private static ReplyResponse instance = null;
	private static final String RESULT_OK = "ok";
	private HeaderInfoResponse headerInfo = null;

	private ReplyResponse() {

	}

	public static synchronized ReplyResponse instance() {
		if (null == instance) {
			instance = new ReplyResponse();
		}
		return instance;
	}

	@Override
	public void initData() {
		setHeaderInfo(null);
	}

	@Override
	public boolean parseJsonObj(JSONObject response) {
		initData();

		if (null == response) {
			LogD.output("Exception: response is null");
			return false;
		}

		if (!checkRespCode(response)) {
			headerInfo = new HeaderInfoResponse();
			headerInfo.parseJsonObj(response);
			setHeaderInfo(headerInfo);
			return false;
		}

		if (response.has(IDs.RESULT)) {
			return RESULT_OK.equals(response.optString(IDs.RESULT));
		}
		return false;
	}

	public HeaderInfoResponse getHeaderInfo() {
		return headerInfo;
	}

	public void setHeaderInfo(HeaderInfoResponse headerInfo) {
		this.headerInfo = headerInfo;
	}

}
